package study.sharding.spring.support.routing;

import org.assertj.core.util.Lists;

import java.util.Collection;
import java.util.List;

/**
 * 数据源 key
 */
public class DataSourceKeyHolder {

    private static final ThreadLocal<String> LOCAL = ThreadLocal.withInitial(() -> "master");

    /* 数据源 key 验证 */
    private static List<Object> KEY_CHECK_LT = Lists.newArrayList();

    public static void setKey(String key) {
        LOCAL.set(key);
    }

    public static String getKey() {
        return LOCAL.get();
    }

    public static void clearKey() {
        LOCAL.remove();
    }

    public static boolean containKey(String key) {
        return KEY_CHECK_LT.contains(key);
    }

    public static boolean addKeys(Collection<? extends Object> keys) {
        return KEY_CHECK_LT.addAll(keys);
    }
}
